<template>
  <view class="container">
    <view class="header">
      <view class="back-arrow" @click="onBack" />
      <text class="title">
        批次结算
      </text>
    </view>
    <!-- 搜索框 -->
    <view class="search-bar">
      <input v-model="keyword" class="search-input" placeholder="搜索货主或批次" confirm-type="search" @confirm="onSearch">
      <image src="@/static/images/search.png" class="search-icon" />
      <view class="filter" @click="toggleFilter">
        <image class="filter-icon" src="@/static/images/filter.png" />
        <span>筛选</span>
      </view>
    </view>
    <!-- 下面的按钮 -->
    <view class="tabs">
      <view class="tab" :class="{ active: activeTab === 0 }" @click="changeTab(0)">
        批次库存
      </view>
      <view class="tab" :class="{ active: activeTab === 1 }" @click="changeTab(1)">
        分类库存
      </view>
    </view>

    <!-- 下面的信息 -->
    <view class="main-container">
      <view class="goods_box" v-for="i in filteredProducts">
        <view class="thegoodsname">
          <view class="font-title">{{ i.name }}</view>
          <view class="font-number">{{ i.number }}</view>
        </view>
        <!-- 下面的时间 -->
        <view class="goods_time">
          {{ i.updatedAt }}
        </view>
        <!-- 右边的东西 -->
        <view class="right_box" :style="getStatusStyle(i.status)">
          {{ i.status }}
        </view>
        <!-- 右边下面 -->
        <view class="right_box_bottom">
          <img style="color: rgba(154, 156, 161, 1);" src="@/static/images/report/right.png" alt="" />
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
  import {
    ref
  } from 'vue';

  function onBack() {
    uni.navigateBack();
  }
  const keyword = ref('');

  function onSearch() {
    console.log('搜索:', keyword.value);
  }

  function toggleFilter() {
    console.log('切换筛选');
  }
  // 按钮
  const activeTab = ref(0)

  function changeTab(tabIndex) {
    activeTab.value = tabIndex
  }
  const filteredProducts = computed(() => {
    switch (activeTab.value) {
      case 0:
        return products.value.filter(item => item.category === '用户');
      case 1:
        return products.value.filter(item => item.category === '货物');
      default:
        return [];
    }
  });

  // 假数据
  const products = ref([{
      number: '005',
      name: '张三',
      status: '在售',
      sid: 0,
      category: '用户',
      updatedAt: '2024-12-13 09:39'
    },
    {
      number: '006',
      name: '李四',
      status: '在售',
      sid: 1,
      category: '用户',
      updatedAt: '2024-12-14 10:45'
    },
    {
      number: '007',
      name: '货物',
      status: '售完',
      sid: 2,
      category: '货物',
      updatedAt: '2024-12-15 14:22'
    },
    {
      number: '008',
      name: '货物',
      status: '结完',
      sid: 3,
      category: '货物',
      updatedAt: '2024-12-15 14:22'
    }
  ]);
  // 颜色
  const getStatusStyle = (status) => {
    if (status === '在售') {
      return {
        backgroundColor: 'rgba(209, 255, 227, 1)'
      };
    } else if (status === '售完') {
      return {
        backgroundColor: 'rgba(250, 207, 165, 1)'
      };
    } else if (status === '结完') {
      return {
        backgroundColor: 'rgba(228, 218, 250, 1.0)'
      };
    } else {
      return {
        backgroundColor: 'rgba(180, 225, 255, 1.0)'
      };
    }
  };
</script>

<style scoped lang="scss">
  .container {
    display: flex;
    flex-direction: column;
    background-color: #f8f8f8;
    min-height: 100vh;
  }

  .header {
    position: relative;
    display: flex;
    align-items: center;
    height: 88rpx;
    padding: 0 20rpx;
    background-color: #ffffff;
    border-bottom: 1rpx solid #f0f0f0;
  }

  .back-arrow {
    position: absolute;
    left: 20rpx;
    width: 30rpx;
    height: 30rpx;
    background: url("@/static/images/back.png") no-repeat center;
    background-size: contain;
  }

  .title {
    font-size: 36rpx;
    color: #333;
    font-weight: bold;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
  }

  .search-bar {
    display: flex;
    align-items: center;
    height: 80rpx;
    padding: 0 20rpx;
    background-color: #ffffff;
    gap: 10%;
  }

  .search-input {
    flex: 1;
    font-size: 25rpx;
    color: #333;
    font-family: sans-serif;
    border-radius: 20px;
    padding: 10rpx 10rpx 10rpx 60rpx;
    background: rgba(245, 247, 250, 1);
    border: 1px solid rgba(229, 229, 229, 1);
    box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.25);
  }

  .search-icon {
    position: absolute;
    object-fit: cover;
    left: 28rpx;
    width: 30rpx;
    padding: 10rpx;
    height: 30rpx;
  }

  .list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .filter {
    display: flex;
    width: 100rpx;
    height: 40rpx;
    font-weight: 500;
    font-size: 32rpx;
  }

  .filter span {
    color: #333;
    margin-left: 4rpx;
    line-height: 40rpx;
  }

  .filter-icon {
    width: 32rpx;
    height: 40rpx;

  }

  /* 按钮 */
  .tabs {
    display: flex;
    justify-content: space-between;
    margin-top: 20rpx;
    border-bottom: 1rpx solid #f5f5f5;
    border: 1rpx solid rgba(67, 207, 124, 1);
    padding: 6rpx;
    background-color: #fff;
  }

  .tab {
    font-size: 32rpx;
    color: #808080;
    padding: 20rpx;
    flex: 1;
    text-align: center;
    border-radius: 5rpx;
    transition: all 0.3s ease;
  }

  .tab.active {
    color: #fff;
    border-radius: 16rpx;
    background-color: rgba(67, 207, 124, 1);
    font-weight: bold;
    box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.25);
  }

  /* 批次信息 */
  .summary {
    padding: 20rpx 40rpx;
    background-color: #ffffff;
  }

  .owe-count {
    font-size: 32rpx;
    color: rgba(128, 128, 128, 1);
    font-weight: 400;
  }

  .owe-count-num {
    color: #FF8D1A;
  }

  /* huowu */
  .goods_box {
    width: 750rpx;
    height: 164rpx;
    margin-top: 20rpx;
    box-shadow: 0 0 5rpx 0 rgba(221, 221, 221, 0.6);
    border: 1rpx solid #efefef;
    position: relative;

    .right_box {
      position: absolute;
      top: 7rpx;
      right: 36rpx;
      // border: 1px solid red;
      background: #43cf7c;
      border-radius: 0 0 7rpx 10rpx;
      color: rgba(128, 128, 128, 1);
      padding: 6rpx 9rpx;
    }

    .right_box_bottom {
      position: absolute;
      display: flex;
      right: 36rpx;
      bottom: 42rpx;
    }

  }

  .thegoodsname {
    margin-top: 24rpx;
    margin-left: 30rpx;
    width: 200rpx;
    height: 60rpx;
    line-height: 60rpx;
    // border: 1px solid red;
    display: flex;
    justify-content: space-between;

    .font-title {
      font-size: 36rpx;
      font-weight: 400;
      color: rgba(0, 0, 0, 1);
    }

    .font-number {
      width: 107rpx;
      height: 41rpx;
      line-height: 41rpx;
      background: #43cf7c;
      border-radius: 7rpx;
      color: #ffffff;
      text-align: center;
      margin-top: 8rpx;
      margin-left: 3rpx;
    }
  }

  .goods_time {
    color: rgba(166, 166, 166, 1);
    font-size: 30rpx;
    margin-top: 7rpx;
    margin-left: 30rpx;
  }
</style>
